
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashSet;
import java.util.Vector;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author olivierm
 */
public class CarnetImpl extends PublisherImpl implements Carnet, Serializable{

    private Vector<ClientImpl> _listesClient = new Vector<ClientImpl>();
    private HashSet<Client> _listesClient2 = new HashSet<Client>();
    private String nomCarnet;
    
    public CarnetImpl(String nom) throws RemoteException{
        super();
        this.nomCarnet = nom;
        //UnicastRemoteObject.exportObject(this); //Plus besoin car PublisherImpl utilise cette méthode dans son constructeur
    }
    
    public  Vector getListeClients() throws RemoteException {
        return this._listesClient;
    }
    
    public HashSet<Client> getListeClients2() throws RemoteException{
        return this._listesClient2;
    }
    
    

    public  boolean créerClient(String nom, String prénom, String téléphone, String adresse) throws RemoteException {
        try{
            ClientImpl cl = new ClientImpl(nom, prénom, téléphone, adresse);
            this._listesClient.addElement(cl);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return false;
    }

    public  ClientImpl rechercherClient(String nom) throws RemoteException {
        try{
            for(int i = 0; i < this._listesClient.size(); i++){
                ClientImpl cl = (ClientImpl)this._listesClient.get(i);
                if(cl.getNom().compareTo(nom) == 0)
                    return cl;
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return null;
    }

    public  boolean supprimerClient(String nom) throws RemoteException {
        try{
            ClientImpl cl = rechercherClient(nom);
            this._listesClient.remove(cl);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return false;
        
    }

    public int getNombreClients() throws RemoteException {
        return this._listesClient.size();
    }

}
